package cn.net.xinyi.xs.model {
	
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	import org.puremvc.as3.multicore.patterns.proxy.Proxy;

	public class LoadChartsProxy extends Proxy {
		
		// Proxy name
		public static const NAME:String = 'LoadChartsProxy';
		
		// Notification constants
		public static const LOAD_CHARTS_SUCCESS:String = 'loadChartsSuccess';
		public static const LOAD_CHARTS_FAILED:String  = 'loadChartsFailed';
		
		// Variables
		private var chartsServiceRO:RemoteObject;
		
		public function LoadChartsProxy() {
			super(NAME);
			chartsServiceRO = new RemoteObject();
			chartsServiceRO.destination = "chartsRemoteObject";
			
			chartsServiceRO.getCharts.addEventListener(ResultEvent.RESULT, onGetChartsResult);
			chartsServiceRO.getCharts.addEventListener(FaultEvent.FAULT, onFault);
		}
		
		public function loadCharts():void {
			chartsServiceRO.getCharts();
		}
		
		private function onGetChartsResult(event:ResultEvent):void {
			sendNotification(LOAD_CHARTS_SUCCESS, event.result);
		}
		
		private function onFault(event:FaultEvent):void {
			sendNotification(LOAD_CHARTS_FAILED, event.fault.faultString);
		}
		
	}
}